<template>
  <div class="search">
    <f-drawer ref="orderDrawer" :title="drawerTitle" width="75%" @submit="handleSubmit" @visibleChange="visibleChange" :show-footer='showFotter'>
      <a-tabs @tabClick="tabClick" :animated='false' :defaultActiveKey="current" v-model="current">
        <a-tab-pane tab="订单信息" key="form1" v-if="drawerVisible">
          <order-info ref="form1" v-if="drawerVisible"></order-info>
        </a-tab-pane>
<!--        <a-tab-pane tab="发货信息" key="form2" v-if="drawerVisible">-->
<!--          <order-send-info ref="form2" v-if="drawerVisible"></order-send-info>-->
<!--        </a-tab-pane>-->
        <a-tab-pane tab="附件资料" key="form3" v-if="drawerVisible">
          <order-attachment ref="form3" v-if="drawerVisible"></order-attachment>
        </a-tab-pane>
      </a-tabs>
    </f-drawer>
  </div>
</template>
<script>
  import OrderInfo from './order_info'
  import OrderSendInfo from './order_send_info'
  import OrderAttachment from './order_attachment'

  export default {
    name: 'orderInfoDrawer',
    props: {
      readOnly: {
        type: Boolean,
        default: false
      },
    },
    data() {
      return {
        refs: this.$refs,
        drawerVisible: false,
        isEdit: false,
        showFotter:null,
        title: '',
        current: 'form1',
        formData: {},
        forms: [
          'form1'
        ]
      }
    },
    methods: {
      showDrawer(data,paymentId) {
        console.info("444444444444444",data)
        this.isEdit = false
        if(paymentId){
          data.paymentId=paymentId;
        }
        if (data && data.orderId) {
          this.isEdit = true
          this.formData = data
        } else {
          this.formData = {}
        }
        this.refs['orderDrawer'].show()
        this.tabClick('form1')
      },
      visibleChange(drawerVisible) {
        this.drawerVisible = drawerVisible
      },
      handleSubmit(opt) {
        this.refs['form2'].handleSubmit((data) => {
            this.formData = data
        })
      },
      tabClick(name) {
        this.current = name
        if(name=='form2'){
          this.showFotter=true;
        }else{
          this.showFotter=null;
        }
        if (this.current === 'form1') {
          this.title = `订单详情(${this.formData.orderNo})`
          if(this.formData.drugsSpec){
            this.titlle+=`规格：${this.formData.drugsSpec} 数量：${this.formData.saleNum} 发货金额：${this.formData.saleAmount}`
          }
        }
        this.$nextTick(() => {
          this.refs[this.current].setData(this.formData, this.readOnly)
        })
      }
    },
    computed: {
      drawerTitle: function() {
        return this.title
      }
    },
    created() {
    },
    components: { OrderSendInfo, OrderInfo,OrderAttachment }
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
